<extend name="./public/frame.html"/>
<block name="content">
    <div class="layer_content">
        <div class="layer_form">
            <div class="down_icon"></div>
            <div class="layer_div">
                <div class="layer_tit">
                    省份：
                </div>
                <div class="layer_control">
                    <select name="province_id" id="province_id" class="w180" lay-filter="province" onclick="getProvinceList();">
                        <option value="">请选择省份</option>
                        <?php foreach($provinceList as $key=>$value):?>
                        <option value="<?php echo $value['region_id'];?>"><?php echo $value['region_name'];?></option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>
            <div class="layer_div">
                <div class="layer_tit">
                    城市：
                </div>
                <div class="layer_control">
                    <select name="city_id" id="city_id" class="w180" lay-filter="city_id">
                        <option value="">请选择城市</option>
                    </select>
                </div>
            </div>
            <div class="layer_div">
                <div class="layer_tit">
                    会员状态：
                </div>
                <div class="layer_control">
                    <select id="member_status" class="w180">
                        <option value="">会员状态</option>
                        <option value="0">未开启</option>
                        <option value="1">已开启</option>
                        <option value="2">已过期</option>
                    </select>
                </div>
            </div>
            <div class="layer_div">
                <div class="layer_tit">
                    开通时间：
                </div>
                <div class="layer_control">
                    <input type="text" class="w180" id="startTime" placeholder="开通会员时间">
                </div>
            </div>
            <div class="layer_div">
                <div class="layer_tit">
                    开通时间：
                </div>
                <div class="layer_control">
                    <input type="text" class="w180" id="endTime" placeholder="开通会员时间">
                </div>
            </div>
            <div class="button_search">
                <button class="layui-btn" data-type="search">搜索</button>
            </div>
        </div>
    </div>
    <table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{:url('Member/index')}', page: true, limit: 10, id:'Member'}" lay-filter="Member">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'member_id', width:70,align:'center', fixed: true, sort: true}">ID</th>
            <th lay-data="{field:'uid', width:80,align:'center'}">会员UID</th>
            <th lay-data="{field:'user_phone', width:150,align:'center'}">手机号</th>
            <th lay-data="{field:'time', width:220,align:'center'}">会员有效时间</th>
            <th lay-data="{field:'phone', width:200,align:'center'}">推荐人</th>
            <th lay-data="{field:'statuName', width:100,align:'center'}">会员状态</th>
            <th lay-data="{field:'levelName', width:100,align:'center'}">会员等级</th>
            <th lay-data="{field:'peronNum', width:150,align:'center'}">推荐人数(钻石/黄金)</th>
            <th lay-data="{field:'one_fr_num', width:150,align:'center'}">车主人数（顺-钻石）</th>
            <th lay-data="{field:'two_fr_num', width:150,align:'center'}">车主人数（顺-黄金）</th>
            <th lay-data="{field:'orderNum', width:150,align:'center'}">订单数量(钻石/黄金)</th>
            <th lay-data="{field:'sum_money', width:100,align:'center'}">累计奖金</th>
            <th lay-data="{field:'wallet_money', width:100,align:'center'}">奖金余额</th>
            <th lay-data="{field:'downloadAppNum', width:150,align:'center'}">APP下载(钻石/黄金)</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:100, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a lay-event="detail">详情</a>
    </script>
    <script>
        layui.use(['table','laydate'], function () {
            var table = layui.table,laydate = layui.laydate;
            table.on('tool(Member)', function (obj) {
                var data = obj.data;
                var uid = data.uid;
                if (obj.event === 'detail') {
                    layer.open({
                        type: 2,
                        title: '会员详情',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/user/detail","uid=")}' + uid
                    });
                }else if (obj.event === 'gengxing') {
                    layer.open({
                        type: 2,
                        title: '会员详情',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/member/gengxing")}'
                    });
                }
            });
            //常规用法
            laydate.render({
                elem: '#startTime'
                ,theme: '#393D49'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#endTime'
                ,theme: '#393D49'
                ,type: 'datetime'
            });
            //搜索
            $('.layui-btn').on('click', function () {
                var phone = $("#phone").val();
                var member_status = $("#member_status").val();
                var startTime = $("#startTime").val();
                var endTime = $("#endTime").val();
                var province_id = $("#province_id").val();
                var city_id = $("#city_id").val();
                if(endTime != '' && startTime > endTime){
                    layer.msg('开始时间不能大于结束时间',{icon: 5});return false;
                }
                table.reload('Member', {
                    url: '/admin/Member/index', where: {
                        "phone": phone,
                        "member_status":member_status,
                        "startTime": startTime,
                        "endTime": endTime,
                        "register_province": province_id,
                        "register_city": city_id
                    }
                });
            })
        });
        function getProvinceList(){
            $("#city_id").empty();
            $("#city_id").append('<option value=>请选择城市</option>');
            var province_id = $("#province_id").val();
            $.ajax({
                url:'{:url("/admin/Franchisee/cityList")}',
                async:true,
                //dataType:'json',
                type:'post',
                data:{'province_id':province_id},
                success:function(res){
                    $("#city_id").append(res);
                },
                error:function(e){
                    layer.msg('请求错误');return false;
                }
            })
        };
    </script>
</block>
